package com.example.juc.demobase;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo01 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Share2 share = new Share2();
        //Runnable接口创建线程
        new Thread(new Runnable() {
            @Override
            public void run() {

            }
        }, "t1").start();
        //Callable接口报错
//        new Thread(new Callable<>() {
//            @Override
//            public void run() {
//
//            }
//        }, "t2").start();
        FutureTask futureTask = new FutureTask<>(
                new Callable<Object>() {
                    @Override
                    public Integer call() throws Exception {
                        System.out.println(Thread.currentThread().getName()+"come inCallAble one");
                        return 2048;
                    }
                }
        );


        FutureTask futureTask2 = new FutureTask<>(
                new Callable<Integer>() {
                    @Override
                    public Integer call() throws Exception {
                        System.out.println(Thread.currentThread().getName()+"come inCallAble two");
                        return 1024;
                    }
                }
        );

        new Thread(futureTask, "t2").start();
        new Thread(futureTask2, "t3").start();

        while (!futureTask.isDone()){
            System.out.println("futureTask isNotDone t2");
        }
        System.out.println(futureTask.get());

        while (!futureTask.isDone()){
            System.out.println("futureTask isNotDone t2");
        }

        System.out.println(futureTask.get());
        System.out.println(futureTask2.get());




    }
}
